package com.xbh.boot_study.srv.impl;

import com.xbh.boot_study.entity.RequestLog;
import com.xbh.boot_study.srv.HelloSrv;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

/**
 * @HelloSrvImpl:
 * @author: ZBoHang
 * @time: 2021/9/23 10:31
 */
@Service
public class HelloSrvJDBCImpl implements HelloSrv {

    private static final Logger S_LOG = LoggerFactory.getLogger(HelloSrvJDBCImpl.class);

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public RequestLog getOne(Integer id) {
        return jdbcTemplate.queryForObject("select * from request_log where id =?", RequestLog.class, id);
    }

    @Override
    public List<RequestLog> getAll() {
        return jdbcTemplate.queryForList("select * from request_log", RequestLog.class);
    }

    @Override
    public void addOne(RequestLog requestLog) {
        jdbcTemplate.update("insert into request_log(ip,port,`time`) values (?,?,?)", requestLog.getIp(),
                requestLog.getPort(), requestLog.getTime());
    }

    @Override
    public void addAll(List<RequestLog> list) {
        jdbcTemplate.batchUpdate("");
    }

    @Override
    public void update(RequestLog requestLog) {
        jdbcTemplate.update("");
    }

    @Override
    public void delete(Integer id) {
        System.out.println(jdbcTemplate.toString());
    }

    @Async
    @Override
    public String testAsync() {

        S_LOG.info("abcdefg ->");
        System.out.println("Async success@@@@@");
        return "async";
    }

}
